<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, [3, 4], [5, [6, 7]]];
            function flat(arr) {
                let result = [];
                for (let i = 0; i < arr.length; i++) {
                    // 判断数组的元素是否为数组
                    if (Array.isArray(arr[i])) {
                        // 如果为数组，就进行递归
                        result = result.concat(flat(arr[i]));
                    } else {
                        // 如果不是数组，直接push到数组里面
                        result.push(arr[i]);
                    }
                }
                return result;
            }
            console.log(flat(arr)); // [1,2,3,4,5,6]
        </script>
    </body>
</html>
